#!/bin/sh
# PCP QA Test No. 1531
# Test Linux ZFS PMDA pool metrics with valgrind
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

_check_valgrind
[ $PCP_PLATFORM = linux ] || _notrun "Linux ZFS PMDA is Linux-specific (uses procfs)"

status=1
$sudo rm -rf $tmp.* $seq.full
trap "cd $here; $sudo rm -rf $tmp.*; exit \$status" 0 1 2 3 15

_filter()
{
    $here/src/sortinst | \
    sed \
        -e '/inst /s/\[[01] /[0-or-1 /' \
	-e "s,$PCP_PMDAS_DIR,PCP_PMDAS_DIR,g" \
	-e "s,$PCP_VAR_DIR,PCP_VAR_DIR,g" \
    #end
}

root=$tmp.root
pmns=$PCP_VAR_DIR/pmns/root_zfs
pmda=$PCP_PMDAS_DIR/zfs/pmda_zfs.so,zfs_init
tgz=$here/linux/zfs-stats.v0.tgz
poolname=pmdazfs_test
$sudo rm -f $PCP_VAR_DIR/config/pmda/153.*
$sudo rm -fr $root
mkdir $root || _fail "root in use when processing $tgz"
cd $root
$sudo tar xzf $tgz
export ZFS_PATH=$root/zfs
echo "== Valgrind checking metric descriptors and values with 1 pool"
_run_valgrind pminfo -L -K clear -K add,153,$pmda -dfmtT -n $pmns zfs.pool | _filter
echo "== Valgrind checking metric descriptors and values with 2 pools"
$sudo cp -R $root/zfs/$poolname $root/zfs/${poolname}1
_run_valgrind pminfo -L -K clear -K add,153,$pmda -dfmtT -n $pmns zfs.pool | _filter
echo "== Valgrind checking metric descriptors and values with 1 pool"
$sudo rm -rf $root/zfs/${poolname}1
_run_valgrind pminfo -L -K clear -K add,153,$pmda -dfmtT -n $pmns zfs.pool | _filter
echo && echo "== done" && echo
cd $here

# success, all done
status=0
exit
